function initChat(webroot){
    function getLastUpdateString(){
         var str = $("#chatMessages .idChatMessage").last().attr('value');
         
         if (str != undefined)
            return str;
         else 
            return '';
    }
    
    //$("#chatMessages").scrollbar();
    placeId = $('#placeId').val();

    $('#buttonSendPost').click(function(){
        var content = $('#contentSendPost').val();
        var urlAjax = $('#formChat').attr('action');
        urlAjax = webroot+'Chats/add';

        $.ajax({
            success: function(data){
                $('#contentSendPost').val('');
            },
            error: function(err, err2){
                alert( err2);
            },
            url: urlAjax,
            data: {content:content, places_id : placeId},
            type: 'POST'
        });

        return false;
    });

    lastScrollTop = 0;
    
    
    updateDisplay();
    

    
    
    function updateDisplay(){
        var theLastUpdateString = getLastUpdateString();
        
        if (lastScrollTop == 0){
            if ($("#chatMessages .chatMessage").last().position() != null){
                lastScrollTop = $("#chatMessages .chatMessage").last().position().top;        
                $("#chatMessages").animate({
                    scrollTop : lastScrollTop
                }, 0);      
            }
        }
        
        $.ajax({
            url : webroot+'chats/getLastMessages',
            success: function(data){
                $("#chatMessages").append(data);
                
                var taille = 0;
                if ($('.chatMessage', $(data)) != null){
                    $('.chatMessage', $(data)).each(function(index, value){
                        taille += $(value).height();
                    });
                }
                /*
                alert("Position : " + $("#chatMessages .chatMessage").last().position().top);
                alert("Taille : " + $("#chatMessages").height());
                */
                /*alert(lastScrollTop);
                 * 
                 */
                if (taille>0){
                    lastScrollTop += taille;
                }

                $("#chatMessages").animate({
                    scrollTop : lastScrollTop
                }, 0);                
            },
            error: function(){
                //alert('sa merde 2');
            },
            complete: function(){
                updateDisplay();                
            },
            data : {lastUpdate : theLastUpdateString, places_id: placeId},
            type : 'POST'
        });        
    }
    
}